<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>影视资源聚合搜索</title>
	<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> 
	
	<!-- ZUI 标准版压缩后的 CSS 文件 -->
	<link rel="stylesheet" href="/css/zui.min.css">		
	<!-- custom css -->
	<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>

<input type="hidden" id="word" value="${word!}" />	

	<div class="container-fixed">
		
		<#include "menu.html">
		
		<!-- 搜索框 begin -->	
		<div class="row i-search">
			<div class="col-md-2"></div>
			<div class="col-md-8">
				<div class="input-group">
				  <div class="input-control search-box search-box-circle has-icon-left has-icon-right search-example" id="searchbox">
				    <input id="inputSearchExample3" type="search" class="form-control search-input" placeholder="搜索">
				    <label for="inputSearchExample3" class="input-control-icon-left search-icon"><i class="icon icon-search"></i></label>
				    <a href="#" class="input-control-icon-right search-clear-btn"><i class="icon icon-remove"></i></a>
				  </div>
				  <span class="input-group-btn">
				    <button class="btn btn-primary" type="button" data-loading-text="正在搜索..." id="search-button">搜索</button>
				  </span>
				</div>
			</div>
			<div class="col-md-2"></div>
		</div>
		<!-- 搜索框 end -->
		
		<!-- 搜索结果 begin -->
		<div class="panel load-indicator" data-loading="正在搜索..." id="search-rs-panel">
			<div class="panel-body">
				<!-- https://tu.ltyuanfang.cn/api/fengjing.php -->
				<!--
				<img src="https://tu.ltyuanfang.cn/api/fengjing.php" width="100%" height="100%" class="img-rounded" alt="搜点影片看看吧">
				-->
				<ul class="nav nav-tabs">
				  <li class="active"><a href="javascript:;" data-tab="tab2Content"><img src="https://movie.douban.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;热播剧集</a></li>
				  <li><a href="javascript:;" data-tab="tab2Content"><img src="https://movie.douban.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;热播电影</a></li>
				  <li><a href="javascript:;" data-tab="tab2Content"><img src="https://movie.douban.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;国产剧</a></li>
				  <li><a href="javascript:;" data-tab="tab2Content"><img src="https://movie.douban.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;韩剧</a></li>
				  <li><a href="javascript:;" data-tab="tab2Content"><img src="https://movie.douban.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;欧美电影</a></li>
				  <!--
				  <li><a href="#" data-tab="tab2Content"><img src="https://www.iqiyi.com/favicon.ico" style="width: 15px; height: 15px;"/>&nbsp;爱奇艺热播</a></li>
				  <li><a href="#" data-tab="tab2Content">腾讯热播</a></li>
				  -->
				</ul>
				<div class="tab-content load-indicator" data-loading="加载中..." id="tab-content">
				  <div class="tab-pane fade active in tab2Content" id="tab2Content">
				    <!--我是标签内容 -->
				    <div data-loading="正在加载..." class="load-indicator loading" style="width: 100%; height: 640px; background: rgb(255, 255, 255)"></div>
				  </div>
				</div>
			</div>
		</div>
		<!-- 搜索结果 end -->
		
	</div>
	
	<!-- 详情（弹框） -->
	<div class="modal fade" id="info-Modal">
	  <div class="modal-dialog">
	    <div class="modal-content">
		  <!--
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
	        <h4 class="modal-title">详情</h4>
	      </div>
	      -->
	      <div class="modal-body" id="video-detail-panel">
			   <!-- 影片详情内容 -->		  
	      </div>
	      <!--
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	        <button type="button" class="btn btn-primary">保存</button>
	      </div>
	      -->
	    </div>
	  </div>
	</div>
	
	<div class="modal fade" id="download-modal">
	  <div class="modal-dialog">
	    <div class="modal-content">
	      <div class="modal-body">
			<input type="hidden" id="code" value="" />
			<input type="hidden" id="vodId" value="" />
			<p id="download-modal-p" style="font-weight: bold;font-size: 25px;"></p>
	        <p><span style="color: red;">Tips:</span> 下载文件为 m3u8 类型文件，建议使用 PotPlayer 播放器打开。</p>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	        <button type="button" class="btn btn-primary" id = "download-modal-ensure">确定</button>
	      </div>
	    </div>
	  </div>
	</div>
	
</body>

<!-- ZUI Javascript 依赖 jQuery -->
<script type="text/javascript" src="/js/jquery.js"></script>
<!-- Jquery UI -->
<script type="text/javascript" src="/js/jquery-ui.min.js"></script>
<!-- ZUI 标准版压缩后的 JavaScript 文件 -->
<script type="text/javascript" src="/js/zui.min.js"></script>
<!-- Art-Template.js -->
<script type="text/javascript" src="/js/template-web.min.js"></script>
<!-- Image Lazy load -->
<script type="text/javascript" src="/js/jquery.lazyload.js"></script>


<!-- 模板 -->
<script id="video-list-item" type="text/html">
<div class="table-responsive">
<table class="table table-hover table-striped">
	<thead>
    <tr>
      <th>名称</th>
      <th>类别</th>
      <th>状态</th>
      <th>时间</th>
      <th>来源</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody class="video-list">
{{each videoList video idx}}
<tr>
  <td>{{video.vodName}}</td>
  <td>{{video.typeName}}</td>
  <td><span class="label {{if video.finished}}label-success{{else}}label-danger{{/if}}">{{video.vodRemarks}}</span></td>
  <td>{{video.vodTime}}</td>
  <td>{{video.vodFromName}}</td>
  <td>
	  <div class="btn-group">
	  <!-- 对话框触发按钮 -->
	  <button type="button" class="btn btn-mini btn-info video-info" data-toggle="modal" data-target="#info-Modal" data-id="{{video.vodId}}" data-from="{{video.vodPlayFrom}}">查看</button>
	  <button type="button" class="btn btn-mini btn-success video-play" data-id="{{video.vodId}}" data-from="{{video.vodPlayFrom}}">播放</button>
	  <button class="btn btn-mini btn-primary video-download" data-from-name="{{video.vodFromName}}" data-name="{{video.vodName}}" data-id="{{video.vodId}}" data-from="{{video.vodPlayFrom}}">下载</button>
	</div>
  </td>
</tr>
{{/each}}
	</tbody>
</table>
</div>
</script>

<!-- 影片详情模板 -->
<script id="video-detail" type="text/html">
<div class="panel" >
<div class="panel-body">
	  <div class="row">
		<div class="col-md-4">
			<img class="lazy" src="img/loading.gif" data-original="{{pic}}" width="160px" height="240px" class="img-thumbnail" alt="{{name}}">
		</div>
		<div class="col-md-8">
			<div class="row">
				<b>名称：{{name}}</b>
			</div>
			<div class="row">
				<b>类型：</b>{{type}}
			</div>
			<div class="row">
				<b>地区：</b>{{area}}
			</div>
			<div class="row">
				<b>语言：</b>{{lang}}
			</div>
			<div class="row">
				<b>年代：</b>{{year}}
			</div>			
			<div class="row">
				<b>状态：</b>{{note}}
			</div>
			<div class="row">
				<b>时间：</b>{{time}}
			</div>
			<div class="row">
				<b>导演：</b>{{director}}
			</div>
			<div class="row">
				<b>演员：</b>{{actor}}
			</div>
			<div class="row">
				<form class="form-inline">
					<div class="form-group">
						<label>选集：</label>
						<select class="form-control input-sm select-ep">
							<% for(var i = playList.length-1; i >= 0; i--){ %>
							  <option value="<%= i %>"><%= playList[i].html %></option>
							<% } %>
						</select>
						<button class="btn btn-sm btn-success select-play" type="button" data-id="{{id}}" data-from="{{vodPlayFrom}}">播放</button>
					</div>
				</form>
			</div>
		</div>
	</div>
  </div>
</div>

<div class="panel">
  <div class="panel-body">
	<b>简介：</b>
    <p>{{desWithoutHtml}}</p>
  </div>
</div>

</script>


<script id="video-hot" type="text/html">
<div class="cards">
{{each hotList vod idx}}
  <div class="col-md-2 col-sm-2 col-lg-2">	
    <a class="card" href="javascript:;" data-name="{{vod.name}}">
		<img class="lazy" src="img/loading.gif" data-original="/douban/image?url={{vod.cover}}" alt="{{vod.name}}" style="height: 226px; width: 100%;"></img>
    	<div class="card-heading"><strong>{{vod.name}}</strong></div>
    </a>
  </div>
{{/each}}
</div>
<!-- 项目切换按钮 -->
<a class="left carousel-control prev-page" href="javascript:;">
  <span class="icon icon-chevron-left"></span>
</a>
<a class="right carousel-control next-page" href="javascript:;">
  <span class="icon icon-chevron-right"></span>
</a>
</script>


<!-- 自定义脚本 -->
<script>

highlightMenu('home');
	
/** 网页加载完成 */
$(function(){
	
	// 菜单处理
	highlightMenu('home');	
	
	// 豆瓣热播
	douban_hot('tv', '热门', PAGE, 'left');

	
	// 搜索
	var wd = $('#word').val();
	if(wd){
		// 搜索框
		wordSearchBox.setSearch(wd);
		searchVideo(wd);
	}
	
});

/** 豆瓣热播 */
function douban_hot(type, tag, page, direction){
	
	$('#tab-content').toggleClass('loading');
	
	$.ajax({
		type: "GET",
        url: "/douban/hot/" + type + "?page=" + page + "&tag=" + tag,
        dataType: "json",
        success: function(data){
			
		   if(data == null || data.length == 0){
			   var emptyHtml = '<img src="https://tu.ltyuanfang.cn/api/fengjing.php" width="100%" height="100%" class="img-rounded" alt="搜点影片看看吧">';
			   $('#search-rs-panel .panel-body').html(emptyHtml);
		   } else {
			   let result = template('video-hot',{'hotList' : data});  //===注意点:  模板上得rows要跟template上得rows对应
           	   $('.tab2Content').html(result) //===直接赋值就可以实现了
		   }
		   
		   
		   
        },
        error: function(err){
			new $.zui.Messager('系统发生错误，请稍后再试！', {
		        icon: 'danger' // 定义消息图标
		    }).show();
		},
		complete: function(){
			$('#tab-content').toggleClass('loading');
			PAGE = page;
			$(".tab2Content").effect( "slide", {
			  'direction': direction
			}, 500, effectCallback);
		}
	});
}

/** 爱奇艺热播 */
function iqiyi_hot(){
	
	$('#tab-content').toggleClass('loading');
	
	$.ajax({
		type: "GET",
        url: "/iqiyi/rank",
        dataType: "json",
        success: function(data){
			
		   if(data == null || data.length == 0){
			   var emptyHtml = '<img src="https://tu.ltyuanfang.cn/api/fengjing.php" width="100%" height="100%" class="img-rounded" alt="搜点影片看看吧">';
			   $('#search-rs-panel .panel-body').html(emptyHtml);
		   } else {
			   let result = template('video-hot',{'hotList' : data});  //===注意点:  模板上得rows要跟template上得rows对应
           	   $('#tab2Content').html(result) //===直接赋值就可以实现了
		   }   
        },
        error: function(err){
			new $.zui.Messager('系统发生错误，请稍后再试！', {
		        icon: 'danger' // 定义消息图标
		    }).show();
		},
		complete: function(){
			$('#tab-content').toggleClass('loading');
		}
	});
}


/** 标签页切换触发 **/
var TAB_NAME = "tv";
var TAG_NAME = "热门";
$('[data-tab]').on('show.zui.tab', function(e) {
    console.log('当前被激活的标签页', e.target);
    console.log('上一个标签页', e.relatedTarget);
    console.log(e.target.attributes.getNamedItem('data-tab'));
    
    // 页码重置为 1
    PAGE = 1;
    
    if(e.target.textContent.includes('热播剧集')){
		TAB_NAME = "tv";
		TAG_NAME = "热门";
		douban_hot(TAB_NAME, TAG_NAME, PAGE);
	} else if(e.target.textContent.includes('热播电影')){
		TAB_NAME = "movie";
		TAG_NAME = "热门";
		douban_hot(TAB_NAME, TAG_NAME, PAGE);
	} else if(e.target.textContent.includes('国产剧')){
		TAB_NAME = "tv";
		TAG_NAME = "国产剧";
		douban_hot(TAB_NAME, TAG_NAME, PAGE);
	} else if(e.target.textContent.includes('韩剧')){
		TAB_NAME = "tv";
		TAG_NAME = "韩剧";
		douban_hot(TAB_NAME, TAG_NAME, PAGE);
	} else if(e.target.textContent.includes('欧美电影')){
		TAB_NAME = "movie";
		TAG_NAME = "欧美";
		douban_hot(TAB_NAME, TAG_NAME, PAGE);
	} else if(e.target.textContent.includes('腾讯热播')){
		
	}
    
});


/** 热播上下页切换 */
var PAGE = 1;
$('.tab2Content').on('click', '.prev-page', function(){
	var page = PAGE - 1
	console.log('next page -> ' + page);
	if(page >= 1){
		douban_hot(TAB_NAME, TAG_NAME, page, 'right');
	} else {
		console.log('这已经是极限啦！');	
	}
	
});
$('.tab2Content').on('click', '.next-page', function(){
	var page = PAGE + 1
	console.log('next page -> ' + page);
	douban_hot(TAB_NAME, TAG_NAME, page, 'left');
});

/**特效回调方法*/
function effectCallback(){
	// 图片懒加载
    $("img.lazy").lazyload({ 
	  threshold : 100, // 设置阀值 
	  effect : "fadeIn" // 设置图片渐入特效 
    });
}


/** 搜索框初始化 */
$('#searchbox').searchBox({
    escToClear: true, // 设置点击 ESC 键清空搜索框
    onSearchChange: function(searchKey, isEmpty) {
        //console.log('搜索框文本变更：', searchKey);
    },
    onPressEnter: function(event) {
        // 处理按下 Enter 键事件
        var wd = $('.search-input').val();
        searchVideo(wd);
    }
});
var wordSearchBox = $('#searchbox').data('zui.searchBox');
	

/** 搜索按钮触发 */	
$('#search-button').on('click',function(){
	var wd = $('.search-input').val();
	searchVideo(wd);
});


// 搜索方法
function searchVideo(wd){
	
	// 显示加载
	$('#search-rs-panel').toggleClass('loading');
	$('#search-button').button('loading');
	
	if(!wd){
		location.href = "/";
	}
	
	$.ajax({
		type: "GET",
        url: "/video/list?wd=" + wd,
        dataType: "json",
        success: function(data){
			
		   if(data == null || data.length == 0){
			   var emptyHtml = '<div class=row>'
			   +'<div class="col-md-12"><img src="/img/empty.jpg" width="100%" height="100%" class="img-rounded"/></div>'
			   +'</div>'
			   $('#search-rs-panel .panel-body').html(emptyHtml);
		   } else {
			   let result = template('video-list-item',{'videoList' : data});  //===注意点:  模板上得rows要跟template上得rows对应
           	   $('#search-rs-panel .panel-body').html(result) //===直接赋值就可以实现了
		   }  
        },
        error: function(err){
			new $.zui.Messager('系统发生错误，请稍后再试！', {
		        icon: 'danger' // 定义消息图标
		    }).show();   
		},
		complete: function(){
			// 关闭加载中
           $('#search-rs-panel').toggleClass('loading');
           $('#search-button').button('reset')
		}
	});
}

/** 点击热播卡片 */
$('#search-rs-panel').on('click', '.card', function(){
	var cardName = $(this).attr('data-name');
	console.log('正在搜索：' + cardName);
	wordSearchBox.setSearch(cardName);
    searchVideo(cardName);
});


/** 查看动态按钮触发事件 */
$('#search-rs-panel').on('click', '.video-info', function(){
	var vodId = $(this).attr('data-id')
	var vodFrom = $(this).attr('data-from')
	//alert(vodId + ',' + vodFrom)
	$.ajax({
		type: "GET",
        url: "/video/detail?vodId=" + vodId + "&code=" + vodFrom,
        dataType: "json",
        success: function(data){
           let result = template('video-detail',data);  //===注意点:  模板上得rows要跟template上得rows对应
           $('#video-detail-panel').html(result) //===直接赋值就可以实现了
           // 图片懒加载
		   $("img.lazy").lazyload({ 
			  threshold : 100, // 设置阀值 
			  effect : "fadeIn" // 设置图片渐入特效 
		   });
        },
        error: function(err){
			new $.zui.Messager('系统发生错误，请稍后再试！', {
		        icon: 'danger' // 定义消息图标
		    }).show();
		}
	});
})

/** 选集播放 */
$('#video-detail-panel').on('click', '.select-play', function(){
	var epIdx = $('.select-ep').val();
	var vodId = $(this).attr('data-id');
	var vodFrom = $(this).attr('data-from');
	window.open('/video/play?vodId=' + vodId + '&code=' + vodFrom + '&ep=' + epIdx, '_blank');
});


/** window.open(“http://www.wlzhys.com“, “_blank”); */
$('#search-rs-panel').on('click', '.video-play', function(){
	var vodId = $(this).attr('data-id');
	var vodFrom = $(this).attr('data-from');
	window.open('/video/play?vodId=' + vodId + '&code=' + vodFrom, '_blank');
});

/** 文件下载 */
$('#search-rs-panel').on('click', '.video-download', function(){
	var vodId = $(this).attr('data-id');
	var vodFrom = $(this).attr('data-from');
	var vodName = $(this).attr('data-name');
	var vodFromName = $(this).attr('data-from-name');
	
	$('#code').val(vodFrom);
	$('#vodId').val(vodId);
	
	$('#download-modal-p').html('是否确定下载【' + vodFromName + '】的《' + vodName + '》');
	
	$('#download-modal').modal('toggle', 'center');	
});

/** 文件下载，确认下载 */
$('#download-modal-ensure').on('click', function(){
	
	var code = $('#code').val();
	var vodId = $('#vodId').val()
	
	$('#download-modal').modal('toggle', 'center');
	
	// window.open('/video/download?vodId=' + vodId + '&code=' + vodFrom, '_blank');
	window.location.href = '/video/download?vodId=' + vodId + '&code=' + code;
});


</script>

</html>